package com.example.edu.Mapper;

import com.example.edu.Dto.ChatListDtoR;
import com.example.edu.Dto.RecordDto;
import com.example.edu.Entity.Chat_Record;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface Chat_RecordMapper {
    @Delete("delete from chat_record where chat_history = #{history_id}")
    void delete(@Param("history_id") int history_id);

    @Select("select count(*) from chat_record where chat_history = #{history_id}")
    int getChatNum(@Param("history_id") int history_id);

    @Select("select chat_id,content,chat_type from chat_record where chat_history = #{history_id} order by chat_id desc limit #{count} offset #{start}")
    List<ChatListDtoR> getChats(@Param("history_id") int history_id, @Param("start") int start, @Param("count") int count);

    @Select("select content,chat_type from chat_record where chat_history = #{history_id} order by chat_id desc limit #{num}")
    List<Chat_Record> getHistoryChats(@Param("history_id") int history_id,@Param("num") int num);

    @Insert("insert into chat_record(chat_history, chat_type, content) values (#{history_id},1,#{question}), (#{history_id},0,#{answer})")
    void addChats(@Param("history_id") int history_id,@Param("question") String question,@Param("answer") String answer);

    @Insert("insert into chat_record(chat_history, chat_type, content) VALUES (#{r.history_id},#{r.chat_type},#{r.content})")
    @Options(useGeneratedKeys = true, keyProperty = "chat_id")
    void addChatsM(@Param("r") RecordDto record);
}
